package com.maisuiit.pattern.singleton;

/**
 * 双重检测锁方式 (因为JVM本质重排序的原因，可能会初始化多次，不推荐使用)
 * @author zhangcc
 * @date 2021-07-13
 */
public class SingletonFifth {

    private static SingletonFifth singletonFifth;

    public SingletonFifth() {
        System.out.println("私有SingletonFifth构造参数初始化");
    }

    public static SingletonFifth getInstance() {
        if (singletonFifth == null) {
            synchronized (SingletonFifth.class) {
                if (singletonFifth == null) {
                    singletonFifth = new SingletonFifth();
                }
            }
        }
        return singletonFifth;
    }
}
